package accountManagementNew.exceptions;

import accountManagementNew.common.base.Result;
import accountManagementNew.common.enums.ResultCodeEnum;
import jakarta.servlet.http.HttpServletRequest;

/**
 * @Author：lihonbin
 * @Version：1.0.0
 * @Date:2025/9/24
 * @Description: 全局异常处理
 */
//@RestControllerAdvice // 表示该类为全局异常处理类
public class GlobalExceptionHandler {

    //@ExceptionHandler
    public Result<String> handlerException(HttpServletRequest request, Exception e) {
        // 对于Swagger相关路径的请求，不进行全局异常处理，直接抛出异常
        String uri = request.getRequestURI();
        if (uri.startsWith("/v3/api-docs") || uri.startsWith("/swagger-ui")) {
            throw new RuntimeException(e);
        }
        
        e.printStackTrace();
        return Result.error(ResultCodeEnum.SERVICE_UNAVAILABLE, "服务暂时不可用");
    }
}